package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.PersonMessage;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.query.PersonMessageQuery;
import cn.wolfcode.trip.base.query.TravelQuery;
import cn.wolfcode.trip.base.service.IPersonMessageService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("personMessage")
public class UserProfilesController {

    @Autowired
    private IPersonMessageService personMessageService;

    @Autowired
    private IUserService userService;

    @GetMapping
    public Object list(Long targetId, int state){
        List<PersonMessage> personMessages = personMessageService.queryLsit(targetId, state);
        return personMessages;
    }


    @PutMapping
    public void changeState(int state,Long targetId){
        personMessageService.changeState(state, targetId);
    }


    @PostMapping
    public void addPersonMessage(Long sourceId, Long targetId, String content){

        personMessageService.insert(sourceId, targetId, content);
    }

    @GetMapping("/{targetId}")
    public Object getUserByTargetId(@PathVariable Long targetId){

        User userByTargetId = userService.getUserByTargetId(targetId);
        return userByTargetId;
    }

}
